package com.losdun.aftersales.jobs;

import com.losdun.aftersales.enums.AftersalesTypeEnum;
import com.losdun.aftersales.service.IInstallService;
import com.losdun.aftersales.service.IRepairService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author Sword.Ye
 * @Date 2025/11/20
 **/
@Slf4j
@Component("delayCheckTask")
public class DelayCheckTask {

    @Autowired
    private IInstallService installService;
    @Autowired
    private IRepairService repairService;
    public void checkInstallDelay(){
        log.info("开始执行逾期安装检查任务");
        installService.queryUnCompletedInstall().forEach(t->{
            log.info("开始处理售后单号:{}", t.getWorkNo());
            //预约测量3天逾期
            if(AftersalesTypeEnum.MEASURE.getValue().equals(t.getType())){
                if(t.getInstallTime().getTime()+1000*60*60*24*3>System.currentTimeMillis()){
                    t.setIsDelay(1);
                    installService.updateById(t);
                }
            }else if(AftersalesTypeEnum.INSTALL.getValue().equals(t.getType())){
                //预约安装5天逾期
                if(t.getInstallTime().getTime()+1000*60*60*24*5>System.currentTimeMillis()){
                    t.setIsDelay(1);
                    installService.updateById(t);
                }
            }
        });
        log.info("结束执行逾期安装检查任务");

    }

    public void checkRepairDelay(){
        log.info("开始执行售后逾期检查任务");
        repairService.queryUnCompletedRepair().forEach(t->{
            log.info("开始处理工单单号:{}", t.getWorkNo());
            //预约测量10天逾期
            if(AftersalesTypeEnum.MEASURE.getValue().equals(t.getType())){
                if(t.getCreateTime().getTime()+1000*60*60*24*10>System.currentTimeMillis()){
                    t.setIsDelay(1);
                    repairService.updateById(t);
                }
            }
        });
        log.info("结束执行售后逾期检查任务");
    }
}
